//(function($, window, document, undefined) {
	var loginButton = document.getElementById('login');
	var accountBox = document.getElementById('account');
	var reg_password = document.getElementById('password');
	var autoLoginButton = document.getElementById("autoLogin");
	var regButton = document.getElementById('reg');
	var mhide = document.getElementById('hide');
	var forgetButton = document.getElementById('forgetPassword');
	var change = 1;
	var reg_phone_number;
	if(localStorage.getItem("user")!==undefined||localStorage.getItem("user")!==null){
		accountBox.value=localStorage.getItem("user");
		reg_phone_number = accountBox.value;
	}else{
		reg_phone_number = accountBox.value;
	}
	mhide.addEventListener('tap', function(event) {
		if(change == 1) {
			mhide.src = '../../img/login/btn_eye_on@3x.png';
			reg_password.type = 'email';
			change = 2;
		} else {
			mhide.src = '../../img/login/btn_eye@3x.png';
			reg_password.type = 'password';
			change = 1;
		}
	});
	loginButton.addEventListener('tap', function(event) {
		var network = true;

		if(network) {
			if(accountBox == "") {
				mui.toast("手机号不能为空");
				return;
			}
			var check_phone_number = /^1([38]\d|4[57]|5[0-35-9]|7[06-8]|8[89])\d{8}$/;
			if(accountBox.value.length == 0) {
				mui.toast("手机号不能为空");
				return;
			}
			if(accountBox.value.length != 11) {
				mui.toast("请输入有效的手机号！");
				return;
			}
			if(!accountBox.value.match(check_phone_number)) {
				mui.toast("请输入有效的手机号！");
				return;
			}
			//密码校验

		}
		var reg_password = document.getElementById("password").value;
		if(reg_password.length == 0) {
			mui.toast("密码不能为空");

			return;
		}
		if(reg_password.length < 6) {
			mui.toast("密码长度不能少于6位！");

			return;
		}
		if(reg_password.length > 16) {
			mui.toast("密码长度不能超过16位！");

			return;
		} 
			$.ajax({
				type: 'get',
		        url: httpAdress + '/api/user/login',
				data: {
					'phone': accountBox.value,
					'passwd': reg_password
				},
				contentType: "application/json; charset=utf-8",
				dataType: 'jsonp',
				jsonp: "callback",
				jsonpCallback: "successCallback",
				success: function(data) {
					console.log(JSON.stringify(data));
					mui.toast(data.msg);
					if(data.status == 1) {
                        localStorage.setItem("userid", data.userid);
                        localStorage.setItem("user", accountBox.value);
						if (GetQueryString("islogin")==1) {
						document.location.href = '../../HTML/home/home.html?k='+accountBox.value;
//						document.location.href = localStorage.getItem("xfhref");
							
						}else if(GetQueryString("islogin")==2){
							document.location.href = '../../HTML/bank/credit_card.html?k='+accountBox.value;
//document.location.href = localStorage.getItem("xfhref");
						}else{
							document.location.href = '../../HTML/home/home.html?k='+accountBox.value;
						}
						
//                     
					} 
				},
				error: function(error) {
					//	                        $("#mask").fadeOut();
					//	                        $("#aloading").css("display", "none");
					mui.toast("登录失败！请重试");
				}
			});

		

		//		window.addEventListener('resize', function() {
		//			oauthArea.style.display = document.body.clientHeight > 400 ? 'block' : 'none';
		//		}, false);
		//

	});
	
//})(window.mui || window, window, document, undefined);